import pandas as pd
from matplotlib import pyplot as plt

df1 = pd.read_excel(r'./data/data2.xls')
# 中文乱码
# plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['font.sans-serif'] = ['Heiti TC']

# 设置画布大小
plt.figure(figsize=(5,3))
labels = df1['省']
sizes = df1['销量']
# 每块颜色

colors = ['red', 'yellow', 'slateblue', 'green','magenta','cyan','darkorange','lawngreen','pink','gold']
plt.pie(sizes, # 绘制数据
        labels=labels, # 添加区域水平标签
        colors=colors,# 设置饼图的自定义填充颜色
        labeldistance=1, # 设置各扇形标签（图例）于圆心的距离
        autopct='%.1f%%', # 设置百分比的格式，保留一位小数
        startangle=90, # 设置饼图的初始角度
        radius=0.5, # 设置饼图半径
        center=(0.2,0.2),#设置饼图的原点
        textprops={'fontsize':9,'color':'k'},# 设置文本标签的属性值
        pctdistance=0.6, # 设置报扽比标签与圆心的距离
        shadow=True, # 阴影
        explode=(0.1,0,0,0,0,0,0,0.1,0.1,0) # 设置分裂
        )
# 设置x,y刻度一致，保证饼图是圆形
plt.axis('equal')
plt.title('各省销量占比')
plt.show()


